package com.whu.lsj;

import java.util.Scanner;

/**
 * 主测试类
 */
public class WordSeg {

	static String train_raw = "data/cs_train-5.utf8";
	static String test_raw = "data/cs_test.utf8";

	static String crf_train_file = "data/crf_train.data";  //CRF训练语料
	static String crf_test_file = "data/crf_test.data";  //CRF测试语料
	static String crf_result_file = "data/crf_result.data";  //CRF测试结果

	static String seg_result_file = "data/seg_result.txt";  //分词结果

	public void train(){
		String learn_cmd = "crf_learn -f 3 -c 4.0 -p 4 template " + crf_train_file + " model_cs";
		Command.exeCMD(learn_cmd,false);
	}
	
	public void test(){
		String test_cmd = "crf_test -m model_cs " + crf_test_file;
		Command.exeCMD(test_cmd,true);
	}

	public static void main(String[] args) {
		WordSeg ws = new WordSeg();
		System.out.print("CRF Begin, Train? 1-Yes 2-No\n");
		Scanner sc = new Scanner(System.in);

		/*训练*/
		int a = sc.nextInt();
		if (a == 1){
			TextProcess.make_train_data(train_raw);  //未处理的训练语料
		//	ws.train();
		}
		System.out.print("Train Finished, Test? 1-Yes 2-No\n");

		/*测试*/
		int b = sc.nextInt();
		if (b == 1){
			TextProcess.TrainToTest();
			TextProcess.make_test_data(test_raw); //未处理的训练语料
			System.out.println("Test begins, Waiting......");
			long start = System.currentTimeMillis();
			ws.test();
			long end = System.currentTimeMillis();
			System.out.println("Done. " + (end - start)/1000+" s");
		}
		ResultFormat.TextFormat();
		System.out.println("Test Finished, Evalute? 1-Yes 2-No");

		/*评分*/
		int c = sc.nextInt();
		if (c == 1){
			AssessCRF.evalute();
		}
	}
}